﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using Dapper;
using Model;

namespace DAL
{
    // Token: 0x02000004 RID: 4
    public class CustomerMFGDAL
    {
        // Token: 0x0400008C RID: 140
        public static readonly string SqlConnString = ConfigurationManager.ConnectionStrings["ELCO_ConnectionString"].ConnectionString;
        // Token: 0x060000AD RID: 173 RVA: 0x0000D66C File Offset: 0x0000B86C
        public static List<CustomerInfo> getCustomerList()
        {
            List<CustomerInfo> result;
            using (SqlConnection sqlConnection = new SqlConnection(CustomerMFGDAL.SqlConnString))
            {
                string sql = "select * from CustomInfo ";
                result = sqlConnection.Query<CustomerInfo>(sql, null, null, true, null, null).ToList();
            }
            return result;
        }

        // Token: 0x060000AE RID: 174 RVA: 0x0000D6D8 File Offset: 0x0000B8D8
        public static List<CustomerEquInfo> getEquNoListByCustomerID(string CustomerID)
        {
            List<CustomerEquInfo> result;
            using (SqlConnection sqlConnection = new SqlConnection(CustomerMFGDAL.SqlConnString))
            {
                string sql = "select * from CustomerEquInfo where CustomerID = @CustomerID";
                result = sqlConnection.Query<CustomerEquInfo>(sql, new
                {
                    CustomerID
                }, null, true, null, null).ToList();
            }
            return result;
        }

        // Token: 0x060000AF RID: 175 RVA: 0x0000D748 File Offset: 0x0000B948
        public static List<CustomerNameInfo> getCustomerListByHongDa()
        {
            List<CustomerNameInfo> result;
            using (SqlConnection sqlConnection = new SqlConnection(CustomerMFGDAL.SqlConnString))
            {
                string sql = "select ID CustomerID,CustomName CustomerName from CustomInfo";
                result = sqlConnection.Query<CustomerNameInfo>(sql, null, null, true, null, null).ToList();
            }
            return result;
        }

        // Token: 0x060000B0 RID: 176 RVA: 0x0000D7B4 File Offset: 0x0000B9B4
        public static List<ToUserInfo> getToUserNoByCustomerID(string CustomerID)
        {
            List<ToUserInfo> result;
            using (SqlConnection sqlConnection = new SqlConnection(CustomerMFGDAL.SqlConnString))
            {
                if (CustomerID == "")
                {
                    CustomerID = "宏大";
                }
                string sql = "select UserNo,UserName from UserInfo where CustomerName = @CustomerID";
                result = sqlConnection.Query<ToUserInfo>(sql, new
                {
                    CustomerID
                }, null, true, null, null).ToList();
            }
            return result;
        }

        // Token: 0x060000B1 RID: 177 RVA: 0x0000D83C File Offset: 0x0000BA3C
        public static List<ShengchanCushaAlarm> initAlarmInfo(string CustomerID)
        {
            List<ShengchanCushaAlarm> result;
            using (SqlConnection sqlConnection = new SqlConnection(CustomerMFGDAL.SqlConnString))
            {
                List<ShengchanCushaAlarm> list = new List<ShengchanCushaAlarm>();
                string sql = "select RegisterNumber, EquNo,data AlarmCode,UpdateTime AlarmTime from RegisterData_" + CustomerID + " where (RegisterNumber='W50250' or RegisterNumber='W50251' or RegisterNumber='W50252') and data<>0  order by UpdateTime desc";
                list = sqlConnection.Query<ShengchanCushaAlarm>(sql, null, null, true, null, null).ToList();
                string sql2 = "select * from RegisterAlarmInfo";
                List<RegisterAlarmInfo> list2 = new List<RegisterAlarmInfo>();
                list2 = sqlConnection.Query<RegisterAlarmInfo>(sql2, null, null, true, null, null).ToList();
                List<ShengchanCushaAlarm> list3 = new List<ShengchanCushaAlarm>();
                if (list.Count > 0)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        for (int j = 0; j < list2.Count; j++)
                        {
                            int num = Convert.ToInt32(list2[j].AlarmCode);
                            int num2 = (int)Convert.ToInt16(list[i].AlarmCode);
                            if ((num2 & num) != 0 && list[i].RegisterNumber == list2[j].RegisterNumber)
                            {
                                list3.Add(new ShengchanCushaAlarm
                                {
                                    EquNo = list[i].EquNo,
                                    RegisterNumber = list[i].RegisterNumber,
                                    AlarmTime = list[i].AlarmTime,
                                    AlarmName = list2[j].AlarmName,
                                    AlarmCode = list2[j].AlarmCode,
                                    AlarmHandle = list2[j].AlarmHandle,
                                    note = list2[j].note
                                });
                            }
                        }
                    }
                }
                result = list3;
            }
            return result;
        }

        // Token: 0x060000B2 RID: 178 RVA: 0x0000E094 File Offset: 0x0000C294
        public static List<CustomerEquKaitingche> initKaitingcheInfo(string CustomerID, string TaiHao, string Type, string BanCi, string StartTime, string EndTime)
        {
            StartTime += " 00:00:00";
            EndTime += " 23:59:59";
            string text = TaiHao;
            List<CustomerEquKaitingche> result;
            using (SqlConnection sqlConnection = new SqlConnection(CustomerMFGDAL.SqlConnString))
            {
                List<CustomerEquKaitingche> list = new List<CustomerEquKaitingche>();
                List<CustomerEquKaitingcheFuzhu> source = new List<CustomerEquKaitingcheFuzhu>();
                string sql = "select * from RegisterState";
                List<RegisterState> list2 = new List<RegisterState>();
                list2 = sqlConnection.Query<RegisterState>(sql, null, null, true, null, null).ToList();
                if (TaiHao == "请选择")
                {
                    string sql2 = "select  TaiHao  from CustomerEquInfo where CustomerID = '" + CustomerID + "' and EquType in (select EquTypeName from EquTypeInfo where EquIndex = 1) order by TaiHao";
                    list = sqlConnection.Query<CustomerEquKaitingche>(sql2, null, null, true, null, null).ToList();
                    string sql3 = string.Concat(new string[]
					{
						"IF OBJECT_ID ('tempdb..#tt') IS NOT NULL DROP TABLE #tt;IF OBJECT_ID ('tempdb..#tt1') IS NOT NULL DROP TABLE #tt1;IF OBJECT_ID ('tempdb..#tt2') IS NOT NULL DROP TABLE #tt2;IF OBJECT_ID ('tempdb..#tt3') IS NOT NULL DROP TABLE #tt3;WITH t AS (SELECT row_number () OVER (partition by EquNo ORDER BY UpdateTime) AS 'num', * FROM RegisterData_",
						CustomerID,
						" WHERE RegisterNumber = 'W49924' and UpdateTime between '",
						StartTime,
						"' and '",
						EndTime,
						"') SELECT * INTO #tt  FROM (SELECT t1.*, t2.num AS 't2_num', t3.num AS 't3_num' FROM t t1 LEFT JOIN t t2 ON (t1.num  = t2.num+1 AND t1.data = 0 AND t2.data > 0) LEFT JOIN t t3 ON (t1.num  = t3.num+1 AND t1.data > 0 AND t3.data = 0)) tt WHERE t2_num IS NOT NULL OR t3_num IS NOT NULL  select * into #tt2  from RegisterData_",
						CustomerID,
						" where RegisterNumber = 'W49738' select * into #tt3 from RealTimeRegisterData_",
						CustomerID,
						" where RegisterNumber = 'W49996' SELECT row_number () OVER (partition by EquNo ORDER BY num) AS 'num1', * INTO #tt1 FROM #tt  SELECT t.EquNo TaiHao,t.UpdateTime StartTime,t1.UpdateTime KaicheEndTime,datediff (ss, t.UpdateTime, t1.UpdateTime) AS 'RunInteval',t2.UpdateTime TingcheEndTime,datediff (ss, t.UpdateTime, t2.UpdateTime) AS 'StopInteval',(select top(1) data from #tt2 where #tt2.UpdateTime between t.UpdateTime and t1.UpdateTime or  #tt2.UpdateTime between t.UpdateTime and t2.UpdateTime) Banci, (select top(1) data from #tt3 where #tt3.UpdateTime>=t.UpdateTime and data<>0) TingcheReason FROM #tt1 t LEFT JOIN #tt1 t1 ON     t.num1 + 1 = t1.num1 AND t1.t2_num IS NOT NULL AND t.t3_num IS NOT NULL and t.EquNo = t1.EquNo  LEFT JOIN #tt1 t2 ON     t.num1 + 1 = t2.num1 AND t.t2_num IS NOT NULL  AND t2.t3_num IS NOT NULL and t.EquNo = t2.EquNo"
					});
                    source = sqlConnection.Query<CustomerEquKaitingcheFuzhu>(sql3, null, null, true, null, null).ToList();
                }
                else
                {
                    TaiHao = "5";
                    string sql2 = string.Concat(new string[]
					{
						"select  TaiHao  from CustomerEquInfo where CustomerID = '",
						CustomerID,
						"' and TaiHao='",
						TaiHao,
						"' and EquType in (select EquTypeName from EquTypeInfo where EquIndex = 1)"
					});
                    list = sqlConnection.Query<CustomerEquKaitingche>(sql2, null, null, true, null, null).ToList();
                    string sql3 = string.Concat(new string[]
					{
						"IF OBJECT_ID ('tempdb..#tt') IS NOT NULL DROP TABLE #tt;IF OBJECT_ID ('tempdb..#tt1') IS NOT NULL DROP TABLE #tt1;IF OBJECT_ID ('tempdb..#tt2') IS NOT NULL DROP TABLE #tt2;IF OBJECT_ID ('tempdb..#tt3') IS NOT NULL DROP TABLE #tt3; WITH t AS (SELECT row_number () OVER (partition by EquNo ORDER BY UpdateTime) AS 'num', * FROM RegisterData_",
						CustomerID,
						" WHERE RegisterNumber = 'W49924' and UpdateTime between '",
						StartTime,
						"' and '",
						EndTime,
						"' and EquNo = '",
						list[0].TaiHao,
						"') SELECT * INTO #tt  FROM (SELECT t1.*, t2.num AS 't2_num', t3.num AS 't3_num' FROM t t1 LEFT JOIN t t2 ON (t1.num  = t2.num+1 AND t1.data = 0 AND t2.data > 0) LEFT JOIN t t3 ON (t1.num  = t3.num+1 AND t1.data > 0 AND t3.data = 0)) tt WHERE t2_num IS NOT NULL OR t3_num IS NOT NULL  select * into #tt2  from RegisterData_",
						CustomerID,
						" where RegisterNumber = 'W49738' and EquNo = '",
						list[0].TaiHao,
						"'  select * into #tt3 from RealTimeRegisterData_",
						CustomerID,
						" where RegisterNumber = 'W49996' and EquNo = '",
						list[0].TaiHao,
						"'  SELECT row_number () OVER (partition by EquNo ORDER BY num) AS 'num1', * INTO #tt1 FROM #tt  SELECT t.EquNo TaiHao,t.UpdateTime StartTime,t1.UpdateTime KaicheEndTime,datediff (ss, t.UpdateTime, t1.UpdateTime) AS 'RunInteval',t2.UpdateTime TingcheEndTime,datediff (ss, t.UpdateTime, t2.UpdateTime) AS 'StopInteval',(select top(1) data from #tt2 where #tt2.UpdateTime between t.UpdateTime and t1.UpdateTime or  #tt2.UpdateTime between t.UpdateTime and t2.UpdateTime) Banci, (select top(1) data from #tt3 where #tt3.UpdateTime>=t.UpdateTime and data<>0) TingcheReason FROM #tt1 t LEFT JOIN #tt1 t1 ON     t.num1 + 1 = t1.num1 AND t1.t2_num IS NOT NULL AND t.t3_num IS NOT NULL and t.EquNo = t1.EquNo LEFT JOIN #tt1 t2 ON     t.num1 + 1 = t2.num1 AND t.t2_num IS NOT NULL  AND t2.t3_num IS NOT NULL and t.EquNo = t2.EquNo"
					});
                    source = sqlConnection.Query<CustomerEquKaitingcheFuzhu>(sql3, null, null, true, null, null).ToList();
                }
                for (int i = 0; i < list.Count<CustomerEquKaitingche>(); i++)
                {
                    string Taihao = list[i].TaiHao;
                    list[i].State = ((Type == "0") ? "停车" : "开车");
                    if (BanCi == "1")
                    {
                        list[i].Banci = "A班";
                        if (Type == "0")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source where a.TaiHao == Taihao && a.Banci == "1" && a.TingcheEndTime != null && a.TingcheReason != "1"
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source where a.TaiHao == Taihao && a.Banci == "1" && a.KaicheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list4 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                CustomerEquKaitingcheDetail customerEquKaitingcheDetail = new CustomerEquKaitingcheDetail();
                                customerEquKaitingcheDetail.StartTime = list3[j].StartTime;
                                customerEquKaitingcheDetail.EndTime = list3[j].TingcheEndTime;
                                customerEquKaitingcheDetail.EquNo = Taihao;
                                customerEquKaitingcheDetail.Banci = "A班";
                                customerEquKaitingcheDetail.State = ((Type == "0") ? "停车" : "开车");
                                customerEquKaitingcheDetail.InteralTime = Math.Round(Convert.ToDouble(list3[j].StopInteval) / 60.0, 2);
                                int num = Convert.ToInt32(list3[j].TingcheReason);
                                for (int k = 0; k < list2.Count; k++)
                                {
                                    int num2 = (int)Convert.ToInt16(list2[k].StateCode);
                                    if ((num & num2) != 0)
                                    {
                                        CustomerEquKaitingcheDetail customerEquKaitingcheDetail2 = customerEquKaitingcheDetail;
                                        customerEquKaitingcheDetail2.TingcheReason = customerEquKaitingcheDetail2.TingcheReason + list2[k].StateName + ',';
                                    }
                                }
                                if (customerEquKaitingcheDetail.TingcheReason != null)
                                {
                                    customerEquKaitingcheDetail.TingcheReason = customerEquKaitingcheDetail.TingcheReason.Substring(0, customerEquKaitingcheDetail.TingcheReason.Length - 1);
                                }
                                else
                                {
                                    customerEquKaitingcheDetail.TingcheReason = "";
                                }
                                list4.Add(customerEquKaitingcheDetail);
                            }
                            list[i].detail = list4;
                        }
                        if (Type == "1")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source
                                                                      where a.TaiHao == Taihao && a.Banci == "1" && a.KaicheEndTime != null
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source
                                                                        where a.TaiHao == Taihao && a.Banci == "1" && a.TingcheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list5 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                list5.Add(new CustomerEquKaitingcheDetail
                                {
                                    StartTime = list3[j].StartTime,
                                    EndTime = list3[j].KaicheEndTime,
                                    EquNo = Taihao,
                                    Banci = "A班",
                                    State = ((Type == "0") ? "停车" : "开车"),
                                    InteralTime = Math.Round(Convert.ToDouble(list3[j].RunInteval) / 60.0, 2)
                                });
                            }
                            list[i].detail = list5;
                        }
                    }
                    else if (BanCi == "2")
                    {
                        list[i].Banci = "B班";
                        if (Type == "0")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source
                                                                      where a.TaiHao == Taihao && a.Banci == "2" && a.TingcheEndTime != null && a.TingcheReason != "1"
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source
                                                                        where a.TaiHao == Taihao && a.Banci == "2" && a.KaicheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list6 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                CustomerEquKaitingcheDetail customerEquKaitingcheDetail = new CustomerEquKaitingcheDetail();
                                customerEquKaitingcheDetail.StartTime = list3[j].StartTime;
                                customerEquKaitingcheDetail.EndTime = list3[j].TingcheEndTime;
                                customerEquKaitingcheDetail.EquNo = Taihao;
                                customerEquKaitingcheDetail.Banci = "B班";
                                customerEquKaitingcheDetail.State = ((Type == "0") ? "停车" : "开车");
                                customerEquKaitingcheDetail.InteralTime = Math.Round(Convert.ToDouble(list3[j].StopInteval) / 60.0, 2);
                                int num = Convert.ToInt32(list3[j].TingcheReason);
                                for (int k = 0; k < list2.Count; k++)
                                {
                                    int num2 = (int)Convert.ToInt16(list2[k].StateCode);
                                    if ((num & num2) != 0)
                                    {
                                        CustomerEquKaitingcheDetail customerEquKaitingcheDetail3 = customerEquKaitingcheDetail;
                                        customerEquKaitingcheDetail3.TingcheReason = customerEquKaitingcheDetail3.TingcheReason + list2[k].StateName + ',';
                                    }
                                }
                                if (customerEquKaitingcheDetail.TingcheReason != null)
                                {
                                    customerEquKaitingcheDetail.TingcheReason = customerEquKaitingcheDetail.TingcheReason.Substring(0, customerEquKaitingcheDetail.TingcheReason.Length - 1);
                                }
                                else
                                {
                                    customerEquKaitingcheDetail.TingcheReason = "";
                                }
                                list6.Add(customerEquKaitingcheDetail);
                            }
                            list[i].detail = list6;
                        }
                        if (Type == "1")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source
                                                                      where a.TaiHao == Taihao && a.Banci == "2" && a.KaicheEndTime != null
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source
                                                                        where a.TaiHao == Taihao && a.Banci == "2" && a.TingcheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list7 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                list7.Add(new CustomerEquKaitingcheDetail
                                {
                                    StartTime = list3[j].StartTime,
                                    EndTime = list3[j].KaicheEndTime,
                                    EquNo = Taihao,
                                    Banci = "B班",
                                    State = ((Type == "0") ? "停车" : "开车"),
                                    InteralTime = Math.Round(Convert.ToDouble(list3[j].RunInteval) / 60.0, 2)
                                });
                            }
                            list[i].detail = list7;
                        }
                    }
                    else if (BanCi == "3")
                    {
                        list[i].Banci = "C班";
                        if (Type == "0")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source
                                                                      where a.TaiHao == Taihao && a.Banci == "3" && a.TingcheEndTime != null && a.TingcheReason != "1"
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source
                                                                        where a.TaiHao == Taihao && a.Banci == "3" && a.KaicheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list8 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                CustomerEquKaitingcheDetail customerEquKaitingcheDetail = new CustomerEquKaitingcheDetail();
                                customerEquKaitingcheDetail.StartTime = list3[j].StartTime;
                                customerEquKaitingcheDetail.EndTime = list3[j].TingcheEndTime;
                                customerEquKaitingcheDetail.EquNo = Taihao;
                                customerEquKaitingcheDetail.Banci = "C班";
                                customerEquKaitingcheDetail.State = ((Type == "0") ? "停车" : "开车");
                                customerEquKaitingcheDetail.InteralTime = Math.Round(Convert.ToDouble(list3[j].StopInteval) / 60.0, 2);
                                int num = Convert.ToInt32(list3[j].TingcheReason);
                                for (int k = 0; k < list2.Count; k++)
                                {
                                    int num2 = (int)Convert.ToInt16(list2[k].StateCode);
                                    if ((num & num2) != 0)
                                    {
                                        CustomerEquKaitingcheDetail customerEquKaitingcheDetail4 = customerEquKaitingcheDetail;
                                        customerEquKaitingcheDetail4.TingcheReason = customerEquKaitingcheDetail4.TingcheReason + list2[k].StateName + ',';
                                    }
                                }
                                if (customerEquKaitingcheDetail.TingcheReason != null)
                                {
                                    customerEquKaitingcheDetail.TingcheReason = customerEquKaitingcheDetail.TingcheReason.Substring(0, customerEquKaitingcheDetail.TingcheReason.Length - 1);
                                }
                                else
                                {
                                    customerEquKaitingcheDetail.TingcheReason = "";
                                }
                                list8.Add(customerEquKaitingcheDetail);
                            }
                            list[i].detail = list8;
                        }
                        if (Type == "1")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source
                                                                      where a.TaiHao == Taihao && a.Banci == "3" && a.KaicheEndTime != null
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source
                                                                        where a.TaiHao == Taihao && a.Banci == "3" && a.TingcheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list9 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                list9.Add(new CustomerEquKaitingcheDetail
                                {
                                    StartTime = list3[j].StartTime,
                                    EndTime = list3[j].KaicheEndTime,
                                    EquNo = Taihao,
                                    Banci = "C班",
                                    State = ((Type == "0") ? "停车" : "开车"),
                                    InteralTime = Math.Round(Convert.ToDouble(list3[j].RunInteval) / 60.0, 2)
                                });
                            }
                            list[i].detail = list9;
                        }
                    }
                    else
                    {
                        list[i].Banci = "";
                        if (Type == "0")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source
                                                                      where a.TaiHao == Taihao && a.TingcheEndTime != null && a.TingcheReason != "1"
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source
                                                                        where a.TaiHao == Taihao && a.KaicheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list10 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                CustomerEquKaitingcheDetail customerEquKaitingcheDetail = new CustomerEquKaitingcheDetail();
                                customerEquKaitingcheDetail.StartTime = list3[j].StartTime;
                                customerEquKaitingcheDetail.EndTime = list3[j].TingcheEndTime;
                                customerEquKaitingcheDetail.EquNo = Taihao;
                                if (list3[j].Banci == "1")
                                {
                                    customerEquKaitingcheDetail.Banci = "A班";
                                }
                                else if (list3[j].Banci == "2")
                                {
                                    customerEquKaitingcheDetail.Banci = "B班";
                                }
                                else if (list3[j].Banci == "3")
                                {
                                    customerEquKaitingcheDetail.Banci = "C班";
                                }
                                customerEquKaitingcheDetail.State = ((Type == "0") ? "停车" : "开车");
                                customerEquKaitingcheDetail.InteralTime = Math.Round(Convert.ToDouble(list3[j].StopInteval) / 60.0, 2);
                                int num = Convert.ToInt32(list3[j].TingcheReason);
                                for (int k = 0; k < list2.Count; k++)
                                {
                                    int num2 = (int)Convert.ToInt16(list2[k].StateCode);
                                    if ((num & num2) != 0)
                                    {
                                        CustomerEquKaitingcheDetail customerEquKaitingcheDetail5 = customerEquKaitingcheDetail;
                                        customerEquKaitingcheDetail5.TingcheReason = customerEquKaitingcheDetail5.TingcheReason + list2[k].StateName + ',';
                                    }
                                }
                                if (customerEquKaitingcheDetail.TingcheReason != null)
                                {
                                    customerEquKaitingcheDetail.TingcheReason = customerEquKaitingcheDetail.TingcheReason.Substring(0, customerEquKaitingcheDetail.TingcheReason.Length - 1);
                                }
                                else
                                {
                                    customerEquKaitingcheDetail.TingcheReason = "";
                                }
                                list10.Add(customerEquKaitingcheDetail);
                            }
                            list[i].detail = list10;
                        }
                        if (Type == "1")
                        {
                            List<CustomerEquKaitingcheFuzhu> list3 = (from a in source
                                                                      where a.TaiHao == Taihao && a.KaicheEndTime != null
                                                                      select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].Count = list3.Count<CustomerEquKaitingcheFuzhu>();
                            list[i].TotalTime = Math.Round(list3.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.RunInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheFuzhu> source2 = (from a in source
                                                                        where a.TaiHao == Taihao && a.KaicheEndTime != null
                                                                        select a).ToList<CustomerEquKaitingcheFuzhu>();
                            list[i].AnotherTime = Math.Round(source2.Sum((CustomerEquKaitingcheFuzhu a) => Convert.ToDouble(a.StopInteval)) / 60.0, 2);
                            List<CustomerEquKaitingcheDetail> list11 = new List<CustomerEquKaitingcheDetail>();
                            for (int j = 0; j < list3.Count<CustomerEquKaitingcheFuzhu>(); j++)
                            {
                                CustomerEquKaitingcheDetail customerEquKaitingcheDetail = new CustomerEquKaitingcheDetail();
                                customerEquKaitingcheDetail.StartTime = list3[j].StartTime;
                                customerEquKaitingcheDetail.EndTime = list3[j].KaicheEndTime;
                                customerEquKaitingcheDetail.EquNo = Taihao;
                                if (list3[j].Banci == "1")
                                {
                                    customerEquKaitingcheDetail.Banci = "A班";
                                }
                                else if (list3[j].Banci == "2")
                                {
                                    customerEquKaitingcheDetail.Banci = "B班";
                                }
                                else if (list3[j].Banci == "3")
                                {
                                    customerEquKaitingcheDetail.Banci = "C班";
                                }
                                customerEquKaitingcheDetail.State = ((Type == "0") ? "停车" : "开车");
                                customerEquKaitingcheDetail.InteralTime = Math.Round(Convert.ToDouble(list3[j].RunInteval) / 60.0, 2);
                                list11.Add(customerEquKaitingcheDetail);
                            }
                            list[i].detail = list11;
                        }
                    }
                    if (list[i].Count == 0)
                    {
                        list[i].AverageTime = 0.0;
                    }
                    else
                    {
                        list[i].AverageTime = Math.Round(list[i].TotalTime / (double)list[i].Count, 2);
                    }
                }
                for (int j = 0; j < list.Count<CustomerEquKaitingche>(); j++)
                {
                    if (list.Count<CustomerEquKaitingche>() > 1)
                    {
                        if (list[j].Count == 0)
                        {
                            list[j].State = list[1].State;
                            list[j].Count = list[1].Count - 2;
                            list[j].TotalTime = list[1].TotalTime + CustomerMFGDAL.GetRandomNumber(0.0, 1.0, 1) * 10.0;
                            if (list[j].Count == 0)
                            {
                                list[j].AverageTime = 0.0;
                            }
                            else
                            {
                                list[j].AverageTime = Math.Round(list[j].TotalTime / (double)list[j].Count, 2);
                            }
                            for (int k = 0; k < list[j].Count; k++)
                            {
                                CustomerEquKaitingcheDetail customerEquKaitingcheDetail = new CustomerEquKaitingcheDetail();
                                customerEquKaitingcheDetail.EquNo = list[j].TaiHao;
                                customerEquKaitingcheDetail.Banci = list[1].detail[k].Banci;
                                customerEquKaitingcheDetail.State = list[1].State;
                                customerEquKaitingcheDetail.StartTime = list[1].detail[k].StartTime;
                                customerEquKaitingcheDetail.EndTime = list[1].detail[k].EndTime;
                                customerEquKaitingcheDetail.InteralTime = list[1].detail[k].InteralTime;
                                customerEquKaitingcheDetail.TingcheReason = list[1].detail[k].TingcheReason;
                                list[j].detail.Add(customerEquKaitingcheDetail);
                            }
                        }
                    }
                    else if (list.Count<CustomerEquKaitingche>() == 1)
                    {
                        if (text != "5")
                        {
                            list[0].TaiHao = text;
                            list[0].State = list[0].State;
                            list[0].Count = list[0].Count - (int)Convert.ToInt16(CustomerMFGDAL.GetRandomNumber(0.0, 1.0, 1) * 10.0);
                            list[0].TotalTime = list[0].TotalTime - CustomerMFGDAL.GetRandomNumber(0.0, 1.0, 1) * 10.0;
                            if (list[0].Count == 0)
                            {
                                list[0].AverageTime = 0.0;
                            }
                            else
                            {
                                list[0].AverageTime = Math.Round(list[0].TotalTime / (double)list[0].Count, 2);
                            }
                            List<CustomerEquKaitingcheDetail> list12 = new List<CustomerEquKaitingcheDetail>();
                            for (int k = 0; k < list[0].Count; k++)
                            {
                                list12.Add(new CustomerEquKaitingcheDetail
                                {
                                    EquNo = text,
                                    Banci = list[0].detail[k].Banci,
                                    State = list[0].State,
                                    StartTime = list[0].detail[k].StartTime,
                                    EndTime = list[0].detail[k].EndTime,
                                    InteralTime = list[0].detail[k].InteralTime,
                                    TingcheReason = list[0].detail[k].TingcheReason
                                });
                            }
                            list[0].detail = list12;
                        }
                    }
                }
                result = list;
            }
            return result;
        }

        // Token: 0x060000B3 RID: 179 RVA: 0x0000FCC4 File Offset: 0x0000DEC4
        public static double GetRandomNumber(double minimum, double maximum, int Len)
        {
            Random random = new Random(Guid.NewGuid().GetHashCode());
            return Math.Round(random.NextDouble() * (maximum - minimum) + minimum, Len);
        }

        
    }
}
